<!--

mc-config:{type:select,options:[{k:'',v:''}]}
-->

<template>
  <el-select ref="elSelect" @blur="blurChange" @change="selectChange" @focus="focusMe" v-model="selectValue" v-bind="$attrs" v-on="$listeners" >
    <slot/>
    <el-option v-for="(item,idx) in options" :key="item.k" :label="item.v" :value="item.k"></el-option>
  </el-select>
</template>

<script>
  import McCommon from "./McCommon";
export default {
  name: 'mc-select',
  data () {
    return {
      options:[],
    }
  },
  props:[
    'mcConfig',
    'value'
  ],
  computed:{
      selectValue:{
        get:function (){
          return this.value;
        },
        set:function (v){
          this.$emit("input",v);
        }
      }
    },
  mounted () {
    this.renderOptions();
  },
  methods:{
      focus(){
        this.$nextTick(()=>{
          this.$refs.elSelect.focus();
        })
      },
      blur(){
        this.$nextTick(()=>{
          this.$refs.elSelect.blur();
        })
      },
      blurChange(){//主动打通校验
        this.$refs.elSelect.dispatch('ElFormItem', 'el.form.blur', [this.selectValue]);
      },
      selectChange(val){//主动打通校验
        this.$refs.elSelect.dispatch('ElFormItem', 'el.form.change', [val]);
      },
      focusMe(e){
        if(window.iframeUi) {
          try {window.iframeUi.fastKey._triggerClickElem(e);}catch(e1) {}
        }
      },
      renderOptions(){
          var _t = this;
          if(this.mcConfig){
            var type = this.mcConfig.type;
            //字典项 就比较简单 固定的 初始化一次
            if(type=='select' && this.mcConfig.options){
                //兼容下数字和字符串转换的类型
                var options=McCommon.util.transeKVType(this.value,this.mcConfig.options,"k","v")
                this.options = options;
            }
          }
      }
  }
}
</script>

<style lang="scss">

</style>
